package cn.org.xuanguang.kepler.hormos.rdb.jpa;


import cn.org.xuanguang.kepler.hormos.rdb.entity.GenericEntity;
import cn.org.xuanguang.kepler.util.JsonUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.sql.JDBCType;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 模型版本表;
 *
 * @author : http://www.chiner.pro
 * @date : 2024-4-23
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(title = "模型版本表", description = "")
@Table(name = "di_version", comment = "模型版本表")
public class DiVersionEntity extends GenericEntity<String> {
    /**
     * 租户号
     */
    @Schema(name = "租户号", description = "")
    @Column(columnName = "tenant_id",
            columnLength = 64,
            nullable = false,
            defaultValue = "tenantId",
            comment = "租户id"
    )
    private String tenantId;
    /**
     * 乐观锁
     */
    @Column(columnName = "revision",
            jdbcType = JDBCType.INTEGER,
            comment = "乐观锁")
    @Schema(name = "乐观锁", description = "")
    private String revision;
    /**
     * 创建人
     */
    @Column(columnName = "created_by")
    @Schema(name = "创建人", description = "")
    private String createdBy;
    /**
     * 创建时间
     */
    @Column(columnName = "created_time",jdbcType = JDBCType.TIMESTAMP)
    @Schema(description = "创建时间", accessMode = Schema.AccessMode.READ_ONLY)
//    @DefaultValue(generator = Generators.CURRENT_TIME)//逻辑默认值
    private LocalDateTime createdTime;
    /**
     * 更新人
     */
    @Column(columnName = "updated_by")
    @Schema(name = "更新人", description = "")
    private String updatedBy;
    /**
     * 更新时间
     */
    @Column(columnName = "updated_time",jdbcType = JDBCType.TIMESTAMP)
    @Schema(description = "更新时间", accessMode = Schema.AccessMode.READ_ONLY)
//    @DefaultValue(generator = Generators.CURRENT_TIME)//逻辑默认值
    private Date updatedTime;
    /**
     * 版本号
     */
    @Column(columnName = "version",jdbcType = JDBCType.DECIMAL,precision = 10, scale = 4)
    @Schema(name = "版本号", description = "")
    private String version;

    //    乐观锁
    @Version
    @Column(columnName = "optlock")
    @Schema(name = "版本号", description = "")
    private String optlock;

    /**
     * json文件内容
     */
    @Column(columnName = "content",jdbcType = JDBCType.LONGVARCHAR,comment = "json文件内容")
    @Schema(name = "json文件内容", description = "")
    private String content;
    /**
     * json文件路径（如果使用存储的话）
     */
    @Schema(name = "json文件路径（如果使用存储的话）", description = "")
    @Column(columnName = "content_path")
    private String contentPath;
    /**
     * 版本状态
     */
    @Schema(name = "版本状态", description = "")
    @Column(columnName = "status")
    @Enumerated(value = EnumType.STRING, mapping = "name")
    private VersionState status;


    public String toString() {
        return JsonUtils.toJSONString(this);
    }
}